package cn.alise.Configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import cn.alise.interceptor.AuthoriInterceptor;
import cn.alise.interceptor.AuthorizationInterceptor;
import cn.alise.interceptor.LogInterceptor;

@Configuration
public class WebAppConfigurer extends WebMvcConfigurerAdapter {
	
	/**
	 * 静态资源路径
	 */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/assets/**").addResourceLocations("/WEB-INF/static/assets/");
        super.addResourceHandlers(registry);
    }
    
    /**
     * 拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
    	
    	// 是否登录判断拦截器
        registry.addInterceptor(new AuthorizationInterceptor()).
        addPathPatterns("/**").excludePathPatterns("/index.html").
        excludePathPatterns("/login/**").excludePathPatterns("/assets/**").
        excludePathPatterns("/favicon.ico").excludePathPatterns("/api/*");
        
        // 权限控制拦截器
        registry.addInterceptor(new AuthoriInterceptor()).
        addPathPatterns("/**").excludePathPatterns("/index.html").
        excludePathPatterns("/login/**").excludePathPatterns("/assets/**").
        excludePathPatterns("/favicon.ico").excludePathPatterns("/api/*");
        
        // 日志拦截器
        registry.addInterceptor(new LogInterceptor()).
        addPathPatterns("/**").excludePathPatterns("/index.html").
        excludePathPatterns("/login/getCaptcha").excludePathPatterns("/login/forward").
        excludePathPatterns("/assets/**").excludePathPatterns("/userAccessLogs/*").
        excludePathPatterns("/global/*").excludePathPatterns("/*/sameCheck*").
        excludePathPatterns("/favicon.ico").excludePathPatterns("/api/*")
        .excludePathPatterns("/login/logout");
        
        super.addInterceptors(registry);
    }
}